perm filename POLL.SAI[SAI,LES] blob sn#836015 filedate 1987-03-09 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00006 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	begin "poll"
C00004 00003				! file i/o
C00006 00004				! totalling procedures
C00010 00005				! main loop
C00011 00006				! combinations
C00013 ENDMK
C⊗;
begin "poll"
require "head" source_file;
!
Reads the sorted output of FROM and counts response combinations.
1987 Feb. 20  First version by Les Earnest.
;
scnbrk(todot,<".[">,null,"IN");

proc lprint(integer l; string s);
    ! prints the leftmost L characters of string S, padding with blanks
      if it is not long enough.;
    if ln(s)<l then print(s,"                                "[1 to l-ln(s)])
      else print(s[1 to l]);

			! file i/o;
string filist;				! list of source files;
integer filemax;			! number of source files;
integer combomax;			! number of combinations of files;

open(inch←getchan,"DSK",1,19,0,400,brk,eof);
while true do begin "lookup"
    boolean fl;
    lookup(inch,filist←ask("Source file="),fl);
    if ¬fl then done;
    print("Can't be opened"&↓);
    close(inch);
    end "lookup";
entout((filist←todot(filist))&".usr");		! write file with same name.USR;
setprint(filist&".hst","B");
if (lop(filist←inlines))≠" " then begin
    print("File not sorted or wrong type"&↓);
    exit;
    end;
filemax←0;
print("			Output from POLL"&↓&↓&"Source Files:"&↓);
for filemax←0 step 1 while ln(filist) do
   print(""&("a"+filemax)," = ",towhites(filist),↓);

combomax←(1 ash filemax) - 1;		! # of combinations of files;
			! totalling procedures;
begin "count"
    integer hosts;		! # of hosts;
    integer hostu,totu;		! users for host, total;
    integer usere,hoste,tote;  	! number of events for user, host, total;
    integer vector;		! event vector for user;
    integer array usercnt,hostcnt,totcnt[1:filemax];	! events seen;
    integer array combo[1:combomax];	! combinations of events;
    string array combs[1:filemax];	! cumulative events;
    string host,ohost;		! current, old host;
    string id,oid;		! current, old user id;

    integer procedure readline;	begin	! read one line of source file;
	string aline;
	integer n;
	if ln(aline←inlines)=0 then return(0);
	host←towhites(aline);
	id←towhites(aline);
	if (n←cvd(aline))≤0 or n>filemax then begin
	    print("Bad file number for ",host," ",id,↓);
	    exit
	    end;
	return(n)
	end "READLINE";
    proc count(integer fil);	begin
	usere←usere + 1;
	usercnt[fil]←usercnt[fil] + 1;
	vector←vector lor (1 ash (fil-1));
	end "COUNT";

    proc newuser;	begin
	hostu←hostu + 1;
	usere←vector←0;
	arrclr(usercnt);
	end "NEWUSER";

    proc newhost;	begin
	hosts←hosts + 1;
	hostu←hoste←0;
	arrclr(hostcnt);
	end "NEWHOST";

    procedure userprint;	begin	! print old users data;
	integer ni;
	cprint(ouch,usere);	! print user event total;
	for ni←1 thru filemax do begin
	    cprint(ouch,usercnt[ni]);       ! and count by type;
	    hostcnt[ni]←hostcnt[ni] + usercnt[ni];
	    end;
	hoste←hoste + usere;
	cprint(ouch," ",ohost," ",oid,↓);
	combo[vector]←combo[vector] + 1;
	oid←id;
	newuser;
	end "USERPRINT";

    procedure hostprint;	begin
	integer ni;
	userprint;
	lprint(20,ohost);
	print(tab,hostu,tab);
	for ni←1 thru filemax do begin
	    print(hostcnt[ni],tab);
	    totcnt[ni]←totcnt[ni] + hostcnt[ni];
	    end;
	print(hoste,↓);
	totu←totu + hostu;
	tote←tote + hoste;
	ohost←host;
	newhost;
	end "HOSTPRINT";
			! main loop;
    integer fileno;			! file index;

    print(↓&"Host                    Users"&↓);
    setformat(4,0);
    hosts←0;
    arrclr(totcnt);
    newhost;  newuser;
    count(readline);
    ohost←host;
    oid←id;
    while (fileno←readline) do begin "read"
	if ¬equ(ohost,host) then hostprint else if ¬equ(oid,id) then userprint;
	count(fileno);
	end "read";
    hostprint;
    print(↓&"            TOTALS  "&tab,totu,tab);
    for fileno←1 thru filemax do print(totcnt[fileno],tab);
    print(tote,↓);
    setformat(0,1);
    print("# hosts = ",hosts,", mean # bboards read = ",tote/totu,↓&↓);

			! combinations;
    setformat(0,0);
    for fileno←1 thru combomax do begin "sweep"
	integer i,t,c;
	string code;
	c←t←0;
	code←null;
	for i←1 thru filemax do if fileno land (1 lsh (i-1)) then begin
	    c←c + 1;			! count & code address bits;
	    code←code&(("a"-1)+i);
	    end;
	for i←1 thru combomax do if (i land fileno)=fileno then t←t + combo[i];
	combs[c]←combs[c]&code&"="&cvs((t*200+totu)/(2*totu))&" ";
	end "sweep";
    print("File combinations (reader %):"&↓);
    for fileno←1 thru filemax do print(combs[fileno],↓);
    exit;
    end "count";
end